<template>
  <div class="bkjl" v-loading="isLoading">
    <el-collapse v-model="activeNames" @change="handleChange">
      <el-collapse-item name="1">
        <template slot="title">
          <div>
            <i
              class="el-icon-document"
              style="font-size: 22px; margin-right: 10px"
            ></i>
            <span style="font-weight: 900; font-size: 16px">报卡记录</span>
          </div>
        </template>
        <div>
          <el-table
            :data="tableData"
            style="width: 100%; margin-top: 15px"
            :header-cell-style="{
              color: '#000',
              backgroundColor: 'rgb(222,234,255)',
            }"
            border
          >
            <el-table-column
              prop="jdDate"
              label="停留未处理时间"
              fixed="left"
              width="200"
            >
            </el-table-column>
            <el-table-column prop="residentName" label="姓名"> </el-table-column>
            <el-table-column prop="gender" label="性别">
              <template slot-scope="scope">
                {{ scope.row.gender | gender }}
              </template>
            </el-table-column>
            <el-table-column prop="bkHosiptalName" label="填报单位">
            </el-table-column>
            <el-table-column prop="chronicType" label="报卡类型">
            </el-table-column>
            <!-- <el-table-column prop="ys1" label="来源"> </el-table-column> -->
            <el-table-column prop="bkTime" label="报卡日期">
              <template slot-scope="scope">
                {{ scope.row.bkTime | time }}
              </template>
            </el-table-column>
            <el-table-column prop="status" label="处理结果">
              <template slot-scope="scope">
                {{ scope.row.status | status }}
              </template>
            </el-table-column>
            <!-- <el-table-column prop="statusReason" label="报卡状态">
        </el-table-column> -->
            <!-- <el-table-column prop="sc" label="档案状态"> </el-table-column> -->
            <el-table-column
              prop="date"
              label="操作"
              fixed="right"
              width="240"
              align="center"
            >
              <template slot-scope="scope">
                <el-button
                  v-if="scope.row.status == 0"
                  type="primary"
                  plain
                  size="mini"
                  style="background-color: #fff; color: rgb(47, 160, 254)"
                  @click="open_dialog(scope.row, true)"
                  >处理</el-button
                >
                <el-button
                  v-if="scope.row.status != 0"
                  type="primary"
                  plain
                  size="mini"
                  style="background-color: #fff; color: rgb(47, 160, 254)"
                  @click="open_dialog(scope.row, false)"
                  >查看</el-button
                >
                <el-button
                  v-if="scope.row.bkDoctorId == DoctorId"
                  type="danger"
                  plain
                  size="mini"
                  style="background-color: #fff; color: rgb(249, 107, 110)"
                  @click="del_arr(scope.row.id)"
                  >作废</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-collapse-item>
    </el-collapse>
    <!-- 弹层开始 -->
    <el-dialog
      title="报卡详情"
      :visible.sync="dialogVisible"
      width="97%"
      style="margin-top: -10vh"
      :before-close="handleClose"
      :append-to-body="true"
      :close-on-click-modal="false"
    >
      <div style="height: 71vh; overflow: auto">
        <BKXQ
          :chronicType="chronicType"
          :tid="tid"
          :info="info"
          v-if="dialogVisible"
        ></BKXQ>
      </div>
      <span slot="footer" class="dialog-footer">
        <span style="color: red">处理备注：</span>
        <el-input
          style="width: 300px; margin-right: 10px"
          v-model="row_info.statusReason"
        ></el-input>
        <el-button type="primary" @click="btn_click(true)" v-if="isBtnShow"
          >接 收</el-button
        >
        <el-button type="danger" @click="btn_click(false)" v-if="isBtnShow"
          >无法处理</el-button
        >
        <el-button @click="handleClose">关 闭</el-button>
        <!--<el-button type="primary" @click="dialogVisible = false"
          >保 存</el-button
        > -->
      </span>
    </el-dialog>
    <!-- 弹层结束 -->
  </div>
</template>
  
  <script>
import BKXQ from "@/views/dialog_info/BKXQ.vue";

export default {
  components: {
    BKXQ,
  },
  data() {
    return {
      activeNames: [],
      tableData: [],
      query: {
        Page: 1,
        Size: 999,
        total: 0,
        residentName: "",
        idCard: "",
        chronicType: "",
        status: "",
        type: "",
        bkTimeFrom: "",
        bkTimeTo: "",
      },
      row_info: {},
      isBtnShow: false,
      dialogVisible: false,
      isLoading: false,
      chronicType: "",
      tid: "",
      info: "",
      DoctorId: window.localStorage.getItem("doctorId"),
    };
  },
  filters: {
    gender(val) {
      var str = "";
      if (val == 1) {
        str = "男";
      }
      if (val == 2) {
        str = "女";
      }
      if (val == 9) {
        str = "未知的性别";
      }
      if (val == 0) {
        str = "未说明的性别";
      }
      return str;
    },
    status(val) {
      var str = "";
      if (val == 0) {
        str = "未处理";
      }
      if (val == 1) {
        str = "已处理";
      }
      if (val == 2) {
        str = "无法处理";
      }
      return str;
    },
    time(val) {
      if (val == null || val == "") {
        return "";
      } else {
        let d = new Date(val); // val 为表格内取到的后台时间
        let month =
          d.getMonth() + 1 < 10 ? "0" + (d.getMonth() + 1) : d.getMonth() + 1;
        let day = d.getDate() < 10 ? "0" + d.getDate() : d.getDate();
        let hours = d.getHours() < 10 ? "0" + d.getHours() : d.getHours();
        let min = d.getMinutes() < 10 ? "0" + d.getMinutes() : d.getMinutes();
        let sec = d.getSeconds() < 10 ? "0" + d.getSeconds() : d.getSeconds();
        let times = d.getFullYear() + "-" + month + "-" + day;
        return times;
      }
    },
  },
  mounted() {
    this.getList();
  },
  methods: {
    getList() {
      this.isLoading = true;
      this.query.idCard = this.$route.query.idCard;
      this.$post("/mbBkMaster/PageList", this.query).then((res) => {
        this.isLoading = false;
        if (res.code != 200) {
          this.$notify.error({
            title: "错误",
            message: res.message,
          });
        } else {
          this.tableData = res.data.records;
        }
      });
    },
    handleChange(val) {
    },
    goto_open() {
      this.dialogVisible = true;
    },
    open_dialog(row, flag) {
      this.isBtnShow = flag;
      this.chronicType = row.chronicType;
      this.tid = row.id + "";
      this.info = JSON.stringify(row);
      this.row_info = row;
      this.dialogVisible = true;
    },
    del_arr(id) {
      this.$confirm("正在进行作废操作，是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          var that = this;
          this.$post("/mbBkMaster/delete?id=" + id).then((res) => {
            if (res.code == 200) {
              that.$notify({
                title: "成功",
                message: "操作成功",
                type: "success",
              });
              this.getList();
            } else {
              that.$notify.error({
                title: "错误",
                message: res.message,
              });
            }
          });
        })
        .catch(() => {});
    },
    handleClose() {
      this.dialogVisible = false;
      this.chronicType = "";
      this.info = "";
      this.tid = "";
    },
    btn_click(flag) {
      var body = this.row_info;
      if (flag) {
        body.status = 1; // 已处理
      } else {
        body.status = 2; // 无法处理
      }
      this.$post("/mbBkMaster/modify", body).then((res) => {
        this.handleClose();
        this.getList();
      });
    },
  },
};
</script>
  
  <style lang="scss" scoped>
.bkjl {
}
</style>